package cn.trasen.his.poc.std.core.init;

import cn.trasen.his.poc.std.api.PocDemoModule;
import cn.trasen.his.poc.std.api.pmodel.WardBedCardProxy;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import pro.shushi.pamirs.boot.common.api.command.AppLifecycleCommand;
import pro.shushi.pamirs.boot.common.api.init.InstallDataInit;
import pro.shushi.pamirs.boot.common.api.init.UpgradeDataInit;
import pro.shushi.pamirs.boot.common.extend.MetaDataEditor;
import pro.shushi.pamirs.core.common.InitializationUtil;
import pro.shushi.pamirs.meta.api.dto.meta.Meta;

import java.util.Collections;
import java.util.List;
import java.util.Map;


@Order(90)
@Component
public class HisOrderModuleInit implements MetaDataEditor, InstallDataInit, UpgradeDataInit {

    @Override
    public boolean init(AppLifecycleCommand command, String version) {
        return false;
    }

    @Override
    public boolean upgrade(AppLifecycleCommand command, String version, String existVersion) {
        return false;
    }

    @Override
    public List<String> modules() {
        return Collections.singletonList(PocDemoModule.MODULE_MODULE);
    }

    @Override
    public int priority() {
        return 0;
    }

    @Override
    public void edit(AppLifecycleCommand command, Map<String, Meta> metaMap) {
        InitializationUtil util = InitializationUtil.get(metaMap, PocDemoModule.MODULE_MODULE, PocDemoModule.MODULE_NAME);
        if (util == null) {
            return;
        }
        modifyViewAction(util);
        modifyServerAction(util);
    }

    private void modifyViewAction(InitializationUtil util) {
        util.modifyViewAction(WardBedCardProxy.MODEL_MODEL, InitializationUtil.DEFAULT_CREATE, createVA -> createVA.setInvisible("true"));
        util.modifyViewAction(WardBedCardProxy.MODEL_MODEL, InitializationUtil.DEFAULT_UPDATE, updateVA -> updateVA.setInvisible("true"));
    }

    private void modifyServerAction(InitializationUtil util) {
        util.modifyServerAction(WardBedCardProxy.MODEL_MODEL, InitializationUtil.DEFAULT_DELETE, deleteSA -> deleteSA.setInvisible("true"));
    }
}
